<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Fast networks for PyBrain &mdash; PyBrain v0.3 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.3',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="PyBrain v0.3 documentation" href="../index.html" />
    <link rel="next" title="Using ODE Environments" href="ode.html" />
    <link rel="prev" title="Extending PyBrain’s structure" href="../tutorial/extending-structure.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="ode.html" title="Using ODE Environments"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="../tutorial/extending-structure.html" title="Extending PyBrain’s structure"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">PyBrain v0.3 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="fast-networks-for-pybrain">
<h1>Fast networks for PyBrain<a class="headerlink" href="#fast-networks-for-pybrain" title="Permalink to this headline">¶</a></h1>
<p>Writing a neural networking framework in Python imposes certain speed
restrictions upon it. Python is just not as fast as languages such as C++
or Fortran.</p>
<p>Due to this, PyBrain has its own spin-off called arac, which is a
re-implementation of its neural networking facilities that integrates
transparently with it.</p>
<p>Depending on the configuration of your system, speedups of <strong>5-10x faster</strong> can
be expected. This speedup might be even higher (ranging into the hundreds) if
you use sophisticated topologies such as MDRNNs. If you want some numbers on
your system, there is a comparison script shipped with PyBrain at
<tt class="docutils literal"><span class="pre">examples/arac/benchmark.py</span></tt>.</p>
<div class="section" id="installation">
<h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
<p>However, the installation process is less easy than for pure Python PyBrain. On
the other hand, it&#8217;s mostly about installing an additional library and telling
PyBrain to use fast networks.</p>
<p>You will find detailed installation instructions for arac on the <a class="reference external" href="http://wiki.github.com/bayerj/arac/installation">arac wiki</a>.</p>
<p>This instructions are work in progress. If you run into difficulties, ask on the
PyBrain mailing list.</p>
</div>
<div class="section" id="usage">
<h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<p>Once you have installed it, there are three ways to use fast networks.</p>
<p>First, the shortcut <tt class="docutils literal"><span class="pre">buildNetwork</span></tt> has a keyword <tt class="docutils literal"><span class="pre">fast</span></tt> which builds an arac
network instead:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">from</span> <span class="nn">pybrain.tools.shortcuts</span> <span class="k">import</span> <span class="n">buildNetwork</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">buildNetwork</span><span class="p">(</span><span class="mf">2</span><span class="p">,</span> <span class="mf">3</span><span class="p">,</span> <span class="mf">1</span><span class="p">,</span> <span class="n">fast</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="o">.</span><span class="n">activate</span><span class="p">((</span><span class="mf">2</span><span class="p">,</span> <span class="mf">3</span><span class="p">))</span>
<span class="go">array([-0.20781205])</span>
</pre></div>
</div>
<p>As you can see by examining the network, it is a special class:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span>
<span class="go">&lt;_FeedForwardNetwork &#39;_FeedForwardNetwork-8&#39;&gt;</span>
</pre></div>
</div>
<p>which is prefixed with an underscore, the Python convention for naming C
implementations of already existing classes. We can import these classes
directly from arac and use them in the same way as PyBrain classes:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">from</span> <span class="nn">arac.pybrainbridge</span> <span class="k">import</span> <span class="n">_FeedForwardNetwork</span><span class="p">,</span> <span class="n">_RecurrentNetwork</span>
</pre></div>
</div>
<p>The third method is to construct a network as a PyBrain network and call the
method <tt class="docutils literal"><span class="pre">convertToFastNetwork</span></tt> afterwards:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">buildNetwork</span><span class="p">(</span><span class="mf">2</span><span class="p">,</span> <span class="mf">3</span><span class="p">,</span> <span class="mf">1</span><span class="p">,</span> <span class="n">fast</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="o">.</span><span class="n">convertToFastNetwork</span><span class="p">()</span>
<span class="go">&lt;_FeedForwardNetwork &#39;_FeedForwardNetwork-18&#39;&gt;</span>
</pre></div>
</div>
<p>However, be cautious with the last method since changes to the PyBrain network
are not reflected in the arac network.</p>
</div>
<div class="section" id="limitations">
<h2>Limitations<a class="headerlink" href="#limitations" title="Permalink to this headline">¶</a></h2>
<p>Since arac is implemented in C++ and currently maintained by only a single
person, arac development is likely to be slower than PyBrain&#8217;s. This might lead
to certain features (e.g. layer types) to be implemented later than the pure
python versions. This also applies to custom layer types. As soon as you have
your layer type, you will not be able to use fast networks anymore &#8211; except if
you chose to also implement them for arac yourself.</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/pybrain_logo.gif" alt="Logo"/>
            </a></p>
            <h3><a href="../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">Fast networks for PyBrain</a><ul>
<li><a class="reference external" href="#installation">Installation</a></li>
<li><a class="reference external" href="#usage">Usage</a></li>
<li><a class="reference external" href="#limitations">Limitations</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="../tutorial/extending-structure.html"
                                  title="previous chapter">Extending PyBrain&#8217;s structure</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="ode.html"
                                  title="next chapter">Using ODE Environments</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/advanced/fast-pybrain.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="ode.html" title="Using ODE Environments"
             >next</a> |</li>
        <li class="right" >
          <a href="../tutorial/extending-structure.html" title="Extending PyBrain’s structure"
             >previous</a> |</li>
        <li><a href="../index.html">PyBrain v0.3 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, CogBotLab &amp; Idsia.
      Last updated on Nov 12, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>